{
	template:`
    <m-page @back="back" title="会员充值">
        <template #bar>
            <div class="padding-left">
                <status type="orderStatus" :value="model.status"></status>
            </div>
            <div class="flex-sub padding-lr text-sm text-right">
                [{{dict('member.order.model.MemberRecharge!type',model.type)}}]<br />
                <span class="text-red text-df padding-left-sm">{{formatAmount(model.payAmount)}}</span>元
            </div>
            <div class="m-buttons padding-right">
                <m-button v-if="model.oid&&model.status=='A'&&editable" @click="next('delete','确定要删除吗？')" type="error">删除</m-button>
                <m-button v-if="editable" @click="save(false)">保存</m-button>
                <m-button v-if="editable" @click="save(true)" type="success">提交</m-button>
                <m-button v-if="model.oid&&confirmable" @click="next('back','确定要退回吗？')" type="warn">退回</m-button>
                <m-button v-if="model.oid&&confirmable" @click="next('confirm','确定要审核通过吗？')" type="success">确认</m-button>
            </div>
        </template>
        <m-top></m-top>
        <m-title>充值信息<template #action>订单编号：{{model.orderNo}}</template></m-title>
        <m-card>
            <div class="cu-form-group">
                <div class="title text-red">会员</div>
                <m-form-item>
                    <div v-if="model.member.oid">{{model.member.realName}} <span class="text-sm">{{model.member.phoneNum}}</span></div>
                    <div v-else-if="editable" class="text-placeholder">请选择会员</div>
                    <template #action>
                        <m-button v-if="editable" @click="selectMember(model)" size="sm">选择</m-button>
                    </template>
                </m-form-item>
            </div>
            <div class="cu-form-group">
                <div class="title text-red">服务员工</div>
                <m-form-item>
                    <div v-if="model.serveUser.oid">{{model.serveUser.realName}} <span class="text-sm">{{model.serveUser.phoneNum}}</span></div>
                    <div v-else-if="editable" class="text-placeholder">请选择员工</div>
                    <template #action>
                        <m-button v-if="editable" @click="selectServeUser(model)" size="sm">选择</m-button>
                    </template>
                </m-form-item>
            </div>
            <div class="cu-form-group">
                <div class="title text-red">付款类型</div>
                <m-dict-option :operable="editable" class="flex-sub" v-model="model.type" type="member.order.model.MemberRecharge!type"></m-dict-option>
            </div>
            <div class="cu-form-group">
                <div class="title text-red">付款金额</div>
                <m-input-number :operable="editable" v-model="model.payAmount" placeholder="请输入付款金额"></m-input-number>
                <div>元</div>
            </div>
            <div class="cu-form-group">
                <div class="title">赠送金额</div>
                <m-input-number :operable="editable" v-model="model.giveAmount" placeholder="请输入赠送金额"></m-input-number>
                <div>元</div>
            </div>
            <div class="cu-form-group">
                <div class="title">赠送积分</div>
                <m-input-number :operable="editable" v-model="model.givePoint" placeholder="请输入赠送积分" format="#,##0"></m-input-number>
            </div>
            <div class="cu-form-group">
                <div class="title text-red">账期</div>
                <m-select-date :operable="editable||confirmable" class="flex-sub" v-model="model.accountDate" placeholder="请选择账期"></m-select-date>
            </div>
            <div class="cu-form-group">
                <div class="title">备注</div>
                <m-input type="textarea" :operable="editable||confirmable" v-model="model.remark" placeholder="请输入备注"></m-input>
            </div>
        </m-card>
        <m-title>登记确认信息</m-title>
        <m-card>
            <div class="padding-xs flex align-center">
                <m-grid :col="2" class="flex-sub">
                    <m-desc title="登记员工">{{model.inputUser.realName}}<small>{{model.inputUser.phoneNum}}</small></m-desc>
                    <m-desc title="登记时间">{{formatDate(model.inputDate,'yyyy-MM-dd HH:mm')}}</m-desc>
                    <m-desc title="确认员工">{{model.confirmUser.realName}}<small>{{model.confirmUser.phoneNum}}</small></m-desc>
                    <m-desc title="确认时间">{{formatDate(model.confirmDate,'yyyy-MM-dd HH:mm')}}</m-desc>
                </m-grid>
                <qrcode v-if="model.oid" :path="'/web/member/main.js?oid='+model.member.oid+'&page=memberRecharge&param.oid='+model.oid"></qrcode>
            </div>
        </m-card>
        <m-title v-if="model.order.oid">相关订单</m-title>
        <m-card v-if="model.order.oid">
            <div class="flex padding-sm align-center" @click="openOrderInfo(model.order.oid)">
                <div class="flex-sub padding-lr-sm">
                    <span class="padding-right-xs">{{model.order.orderNo}}</span>
                    {{formatDate(model.order.inputDate,'yyyy-MM-dd')}} /
                    实付{{formatAmount(model.order.payAmount)}}元
                </div>
                <status type="orderStatus" :value="model.order.status"></status>
            </div>
        </m-card>
    </m-page>
	`,
	props: ['param','parentVue'],
	data:function(){
		return {
		    model:{member:{},serveUser:{},inputUser:{},inputStore:{},confirmUser:{},order:{}},
		    editable:false,
		    confirmable:false
		};
	},
	mounted(){
	    this.model.oid=this.param.oid;
	    this.loadModel();
	},
	methods:{
	    loadModel:function(fn){
            this.requestData('action/order/memberRecharge/getInfo',
                {oid:this.model.oid},
                (data)=>{
                    if(data.code==0){
                        this.model=data.model;
                        this.editable=data.editable;
                        this.confirmable=data.confirmable;
                        if(fn) fn();
                    }else{
                        this.remind().error(data.msg);
                    }
                }
            );
	    },
        selectMember:function(model){
            let selectOid=model.member?model.member.oid:'';
	        this.openPage('common/selectMember.js',{title:'选择会员',selectOid:selectOid},(flag,obj)=>{
	            if(flag){
	                model.member=obj;
                }
	        });
        },
        selectServeUser:function(model){
            let selectOid=model.serveUser?model.serveUser.oid:'';
	        this.openPage('common/selectUser.js',{title:'选择店长',selectOid:selectOid,storeOid:config.store.oid},(flag,obj)=>{
	            if(flag){
	                model.serveUser=obj;
                }
	        });
        },
        save:function(isSubmit){
            let fn=()=>{
                this.requestData('action/order/memberRecharge/'+(isSubmit?'submit':'save'),
                    {model:this.model},
                    (data)=>{
                        if(data.code==0){
                            this.remind().success(data.msg);
                            this.model.oid=data.oid;
                            if(isSubmit){
                                this.back(true,this.model);
                            }else{
                                this.loadModel(()=>{
                                    this.setBack(true,this.model);
                                });
                            }
                        }else{
                            this.remind().error(data.msg);
                        }
                    }
                );
            }
            if(isSubmit){
                this.confirm("保存并提交","确定要保存并提交吗？",fn);
            }else{
                fn();
            }
        },
        next:function(oper,confirmAlert){
            this.confirm('操作提示',confirmAlert||'确定要这样操作吗？',()=>{
                this.requestData('action/order/memberRecharge/'+oper,
                    {model:this.model},
                    (data)=>{
                        if(data.code==0){
                            this.remind().success(data.msg);
                            this.back(true,this.model);
                        }else{
                            this.remind().error(data.msg);
                        }
                    }
                );
            });
        },
	    openOrderInfo:function(oid){
	        this.openPage('order/orderInfo.js',{oid:oid},(flag,obj)=>{
	            if(flag){
                }
	        });
	    }
	}
}